const reqUrl = {
  login: global_BASEURL + "/api/DtUser/login", //登陆
  getFeeItem: global_BASEURL + "/api/NsFinance/getFeeItem", //获取收费项目列表
  addBill: global_BASEURL + "/api/NsFinance/addBill", //记账接口
  getPatientOfMyWard: global_BASEURL + "/api/NsPatient/getPatientOfMyWard", //获取区患者

  patientBaseInfo: global_BASEURL + "/api/DtPatient/baseInfo", //患者信息
  addSign: global_BASEURL + "/api/DtSign/addSign", //体征录入
  batchAddSign: global_BASEURL + "/api/NsRecord/batchAddSign", //批量体征录入

  getTodayLineTask: global_BASEURL + "/api/NsTask/getTodayLineTask", //今日排药任务列表
  getLineAdvTask: global_BASEURL + "/api/NsTask/getLineAdvTask", //今日排药任务列表
  submitLineAdvTask: global_BASEURL + "/api/NsTask/submitLineAdvTask", //排药数据提交

  // 执行
  getTodayPoTask: global_BASEURL + "/api/NsTask/getTodayPoTask", //今日任务 ----- 口服药
  getTodayInfuseTask: global_BASEURL + "/api/NsTask/getTodayInfuseTask", //执行---输液执行任务
  submitExeTask: global_BASEURL + "/api/NsTask/submitExeTask", //执行---输液执行任务
  getAdviseRecList: global_BASEURL + "/api/NsAdvise/getAdviseRecList", //执行---输液执行任务



  getTodayMatchTask: global_BASEURL + "/api/NsTask/getTodayMatchTask", //获取配药任务患者列表
  getTodayCheckTask: global_BASEURL + "/api/NsTask/getTodayCheckTask", //获取配药复核任务患者列表
  getAdviseVoByQrNo: global_BASEURL + "/api/NsAdvise/getAdviseVoByQrNo", //扫码获取医嘱信息
  submitMatchTask: global_BASEURL + "/api/NsTask/submitMatchTask", //提交配药
  submitCheckTask: global_BASEURL + "/api/NsTask/submitCheckTask", //提交复核配药
  getTodayFinishMatchTask:
    global_BASEURL + "/api/NsTask/getTodayFinishMatchTask",
  getTodayFinishCheckTask:
    global_BASEURL + "/api/NsTask/getTodayFinishCheckTask",

  //巡视
  getTodayTourInfusionTask:
    global_BASEURL + "/api/NsTour/getTodayTourInfusionTask", //获取输液巡视任务列表
  getNormalTourTaskList: global_BASEURL + "/api/NsTour/getNormalTourTaskList", //获取患者常规巡视列表
  getPtOxyRec: global_BASEURL + "/api/NsTour/getPtOxyRec", //获取患者用氧巡视列表
  modifyTourNormal: global_BASEURL + "/api/NsTour/modifyTourNormal", //获取患者用氧巡视列表
  getOxygenTourRecByDate: global_BASEURL + "/api/NsTour/getOxygenTourRecByDate", //吸氧巡视记录
  getInfusionTourRecByDate:
    global_BASEURL + "/api/NsTour/getInfusionTourRecByDate", //输液巡视记录
  getNormalTourRecByDate: global_BASEURL + "/api/NsTour/getNormalTourRecByDate", //常规巡视记录

  addOxyRec: global_BASEURL + "/api/NsTour/addOxyRec", //添加吸氧巡视
  modifyTourOxygen: global_BASEURL + "/api/NsTour/modifyTourOxygen", //添加吸氧巡视
  addTourNormal: global_BASEURL + "/api/NsTour/addTourNormal", //添加常规巡视

  addTourInfusion: global_BASEURL + "/api/NsTour/addTourInfusion", //编辑输液巡视

  getFallAssessListByPno: global_BASEURL + "/api/NsTour/getFallAssessListByPno", //获取患者的跌倒评估
  addFallAssess: global_BASEURL + "/api/NsRecord/addFallAssess", //添加跌倒评估

  // 新接口
  getTodayPoTaskByPtList:
    global_BASEURL2 + "/api/advTask/getTodayPoTaskByPtList" //获取今日口服药执行任务
};

/**
 * NetWork_Post post请求方法
 */
const NetWork_Post = function (net_api, bodyData, callback, netOptions) {
  let opt_headers, opt_error;
  if (typeof netOptions === "object") {
    opt_headers = netOptions["headers"];
    opt_error = netOptions["error"];
  }
  let post_header = opt_headers
    ? opt_headers
    : {
      // Accept: 'application/json'
      // 'Content-Type': 'application/json'
    };
  let post_error = opt_error
    ? opt_error
    : {
      code: "-1",
      msg: "请求失败"
    };

  let url = reqUrl[net_api];
  let fetchOptions = {
    method: "POST",
    headers: post_header,
    body: bodyData
  };

  // console.log(url, fetchOptions);

  fetch(url, fetchOptions)
    .then(response => response.text())
    .then(responseText => {
      // console.log(responseText);
      let responseData = JSON.parse(responseText);
      callback(responseData);
    })
    .catch(error => {

      callback(post_error);
    })
    .done();
};
/**
 * NetWork_Get
 */
const NetWork_Get = function (net_api, callback, netOptions) {
  let url = reqUrl[net_api];
  let opt_error;
  if (typeof netOptions === "object") {
    opt_error = netOptions["error"];
  }
  let get_error = opt_error
    ? opt_error
    : {
      status: "-1",
      msg: "请求失败"
    };
  //类似封装后的ajax方法
  fetch(url, {
    method: "GET",
    credentials: "include"
  })
    .then(response => response.text())
    .then(responseText => {
      let responseData = JSON.parse(responseText);
      callback(responseData);
    })
    .catch(error => {
      callback(get_error);
    });
};
const NetApi = {
  NetWork_Post,
  NetWork_Get
};

module.exports = NetApi;
